package com.kele

import scala.collection.mutable

/**
 * @ClassName : TwoNumSum
 * @Author : kele
 * @Date: 2022/10/25 22:08
 * @Description :
 */
object TwoNumSum2 {

  def solution(input: Array[Int], target: Int): Array[Int] = {

    val map = mutable.HashMap[Int, Int]()
    var result = new Array[Int](2)

    input.zipWithIndex.foreach(x => {
      val index = x._2
      val value = x._1

      if (map.keySet.contains(target - value)) {
        result(0) = index
        result(1) = map(target - value)
      } else {
        map.put(value, index)
      }
    })
    result
  }

  def main(args: Array[String]): Unit = {
    println(solution(Array[Int](2, 6, 7, 9, 11), 8).toBuffer)
  }

}
